<?php
/**
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT		: Rubik Ultimate Framework
 * @version 	: 1.1
 * COPYRIGHT    : 2008
 * ------------------------------------------------------
 * 
 * Created on	:  Jun 19, 2008
 * 
 */

// no direct access
defined ( '_FW_EXEC' ) or die ( 'Restricted access' );

RCoreImporter::cls("dbo.AbstractRubikDTO" );

class AbstractDTO extends AbstractRubikDTO {
	
	/**
	 * Constructor
	 *
	 * @param string $from this can be a from clause of just table name.
	 * @param string $where the where clause of this dbo
	 * @param string $orderBy the ORDER BY clause
	 * @param Database $db database object of this DB Info.
	 */
	function __construct($from = '', $where = '', $orderBy = '', $db = null) {
		if (empty ( $db )) {
			$db = &SysDatabase::getInstance ();
		}
		parent::__construct ( $from, $where, $orderBy, $db );
	}

	/**
	 * Get all items inside
	 * @param string $where
	 * @param string $orderBy
	 * @param DataBase $db
	 * @return array
	 */
	public static function getListAll($classNameOrObject, $where='', $orderBy = '', $db = null) {
		static $list;
		if (!$list) {
			if (is_string($classNameOrObject)) {
				$dto = new $classNameOrObject();
			}
			else {
				$dto = $classNameOrObject;
			}
			$list = SysDatabase::loadObjectList($dto->getSelectSQL());
		}
		return $list;
	}	
	
	/**
	 * Build the new where string from the input where with the new extended where
	 * @param string $where
	 * @param string $extWhere
	 * @return string
	 */
	public static function buildMoreWhere($where, $extWhere) {
		if (empty($where)) {
			$where = $extWhere;
		}
		else {
			$where .= " AND ($extWhere)";
		}
		
		return $where;
	}
}
?>